package com.digdes.calendar.gwt.client.widget;

import com.digdes.calendar.gwt.client.dto.UserDTOImpl;

import com.digdes.calendar.gwt.client.service.CalendarService;
import com.digdes.calendar.gwt.client.service.CalendarServiceAsync;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

import com.google.gwt.user.client.ui.HTML;


public class CreateParticipantDialog extends DialogBox {

    TextBox name = new TextBox();
    TextBox surname = new TextBox();
    TextBox middlename = new TextBox();
    TextBox emailtb = new TextBox();
    TextBox posttb = new TextBox();
    public CreateParticipantDialog() {

        VerticalPanel vp = new VerticalPanel();
        HorizontalPanel hp = new HorizontalPanel();
        vp.setSize("100px", "200px");

        setAnimationEnabled(true);
        setGlassEnabled(true);

        Button addUser = new Button("Create");
        Button close = new Button("Close");

        addUser.setSize("100px", "30px");
        close.setSize("100px", "30px");

        CheckBox check = new CheckBox("Отослать на почту");


        addUser.addClickHandler(new ClickHandler() {

            //@Override
            public void onClick(ClickEvent event) {

                UserDTOImpl addUserDTO = new UserDTOImpl();
                addUserDTO.setEmail(emailtb.getText());
                addUserDTO.setPost(posttb.getText());
                addUserDTO.setSurname(surname.getText());
                addUserDTO.setName(name.getText());
                addUserDTO.setPatronymic(middlename.getText());

                final CalendarServiceAsync calendarservice = GWT.create(CalendarService.class);
                calendarservice.addUser(addUserDTO, new AsyncCallback<Long>(){

                    public void onFailure(Throwable e){

                    }
                        public void onSuccess(Long result){
                                Window.alert("Success");
                            CreateParticipantDialog.this.hide();

                        }

                }
                 );

            }
        });

        close.addClickHandler(new ClickHandler() {

            //@Override
            public void onClick(ClickEvent event) {
                CreateParticipantDialog.this.hide();
            }
        });


        vp.add(new HTML("Введите: имя"));
        vp.add(name);
        vp.add(new HTML("Фамилию"));
        vp.add(surname);
        vp.add(new HTML("Отчество"));
        vp.add(middlename);
        vp.add(new HTML("Email"));
        vp.add(emailtb);
        vp.add(new HTML("Должность"));
        vp.add(posttb);

        vp.add(new HTML("<br>"));
        hp.add(addUser);
        hp.add(close);
        vp.add(hp);
        setWidget(vp);

    }

}
